<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>发送消息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<LINK href="styles/stylewang.css"  type=text/css rel=stylesheet>
	<LINK href="./styles/sciencee.css"  type=text/css rel=stylesheet>
	<script language=javascript>
		var attachCount=1;
		function selectReceiver(){
			window.open("<%=path%>/message/SelectUser.jsp?opener=receiver","selectUser",'top=150,left=250,scrollbars=yes,dialog=yes,modal=yes,width=620,height=320,resizable=yes');
		}
		function selectCopyer(){
			window.open("<%=path%>/message/SelectUser.jsp?opener=copyer","selectUser",'top=150,left=250,scrollbars=yes,dialog=yes,modal=yes,width=620,height=320,resizable=yes');
		}
		function sendMessage(){
			var IframeID=document.getElementById("cws_Composition").contentWindow;
			var con=document.getElementById("content");
			con.value=IframeID.document.body.innerHTML;
			var form1=document.getElementById("form1");
			form1.submit();
		}
		
		function addAttach(){
			attachCount=attachCount+1;
			var table=document.getElementById("attach");
			if(navigator.appName=="Microsoft Internet Explorer"){
				var row=table.insertRow();
				var cell=row.insertCell();
				cell.innerHTML+="<bean:message key='message.attachment'/>:<input type='file' id='image"+attachCount+"' name='img"+attachCount+"' onchange='javascript:ShowImage(this.value,this.id)'>";
			}else{
				var tr=document.createElement("tr");
				tr.innerHTML+="<td><bean:message key='message.attachment'/>:<input type='file' id='image"+attachCount+"' name='img"+attachCount+"' onchange='javascript:ShowImage(this.value,this.id)'></td>";
				table.appendChild(tr);
			}
			addImg();
		}
		function addImg(){
			var td=document.getElementById("imgshow");
			td.innerHTML+="<td><img id='showimage"+attachCount+"' STYLE='visibility:hidden' height='100px' width='100px'></td>";
		}
		function ShowImage(value,imgId)
    {
      //alert(value);
      //检测盘符
      //alert(value.indexOf(':'));
      //检测文件是否有扩展名
      //alert(value.length-value.lastIndexOf('.'));
      //取文件扩展名
      //alert(value.substr(value.length-3,3));
      //检测文件扩展名是否合法
      //alert(CheckExt(value.substr(value.length-3,3)));
      var img=document.getElementById("show"+imgId);
        if(value.length>5&&value.indexOf(':')==1&&(value.length-value.lastIndexOf('.'))==4&&CheckExt(value.substr(value.length-3,3)))
        {

            img.src="file:///"+value;
            img.alt="本地图片预览";
            img.style.visibility="visible";
        }
        else
        {
     img.style.visibility="hidden";
     alert("the file is not a image!");
     document.getElementById(imgId).value="";
     }
    }
    //检查扩展名是否合法,合法返回True
    function CheckExt(ext)
    {
     //这里设置允许的扩展名
     var AllowExt="jpg|gif|jpeg|png|bmp";
     var ExtOK=false;
   var ArrayExt;
   if(AllowExt.indexOf('|')!=-1)
   {
    ArrayExt=AllowExt.split('|');
    for(i=0;i<ArrayExt.length;i++)
    {
     if(ext.toLowerCase()==ArrayExt[i])
     {
      ExtOK=true;
      break;
     }
    }
   }
   else
   {
    ArrayExt=AllowExt;
    if(ext.toLowerCase()==ArrayExt)
    {
     ExtOK=true;
    }
   }
   return ExtOK;
    }
	</script>
  </head>
  
  <body>
  <div id="bgwin">
    <form id="form1" action="<%=path %>/message/send.do" method="POST" enctype="multipart/form-data">
    <table width="480" cellpadding="0" cellspacing="2">
    	<tr>
    		<td><bean:message key="message.receiver"/>:<%
    			String str=request.getParameter("receiver");
    			if(str!=null){ 
    			str=new String(str.getBytes("ISO-8859-1"), "utf-8");
    		%><input type="text" id="receiver2" name="receiver2" value="<%=str %>">
    		  <%}else{%><input type="text" id="receiver" name="receiver" >
    		<%} %><input name="button" type="button" onClick="selectReceiver();" value="<bean:message key='message.selectuser'/>"></td>
    	</tr>
    	<tr>
    		<td>
    			&nbsp;&nbsp;<bean:message key="message.copyer"/>:<input type="text" id="copyer" name="copyer" >
    			<input type="button" value="<bean:message key='message.selectuser'/>" onClick="selectCopyer();">    		</td>
    	</tr>
    	<tr>
   		  <td>&nbsp;&nbsp;<bean:message key="message.title"/>:<input type="text" name="title"></td>
    	</tr>
    	<tr>
    		<input id="content" type="hidden" name="content" >
    		<td><%@ include file="editor.jsp"%></td>
    	</tr>
    	<tr >
    		<table id="attach">
    		<tr><td >
    		<bean:message key="message.attachment"/>:<input type="file" id="image1" name="img1" onChange="javascript:ShowImage(this.value,this.id)"><input type="button" onClick="addAttach();" value="<bean:message key='message.addattach'/>">
    		</td></tr>
    		</table>
    	</tr>
    	<tr>
    	<div id="imgshow">
    		<td ><img id="showimage1" STYLE="visibility:hidden" height="100px" width="100px"></td>
    	</div>
    	</tr><div align="center">
    	<tr>
    		<td>
    			<input type="button" value="<bean:message key='message.send'/>" onClick="sendMessage();">
    			<input type="button" value="<bean:message key='close'/>" onClick="window.close();" ></td>
    	</tr></div>
    </table>
    
    </form>
  </body>
</html>
